package com.boot.project.service.impl;

import com.boot.project.dao.CouponCardDao;
import com.boot.project.domain.CouponCardDO;
import com.boot.project.service.CouponCardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CouponCardServiceImpl implements CouponCardService {
    @Autowired
    private CouponCardDao couponCardDao;

    @Override
    public List<CouponCardDO> allCards() {
        return couponCardDao.allCards();
    }

    @Override
    public Map<String, Object> updateCard(CouponCardDO couponCardDO) {
        Map<String, Object> mapResult = new HashMap<>();
        Integer updateFlag = couponCardDao.updateCard(couponCardDO);
        if (updateFlag >= 0) {
            mapResult.put("msg", "ok");
            mapResult.put("code", 200);
            return mapResult;
        } else {
            mapResult.put("msg", "error");
            mapResult.put("code", 500);
            return mapResult;
        }
    }

    @Override
    public Map<String, Object> saveCard(CouponCardDO couponCardDO) {
        Map<String, Object> mapResult = new HashMap<>();
        Integer saveFlag = couponCardDao.saveCard(couponCardDO);
        if (saveFlag >= 0) {
            mapResult.put("msg", "ok");
            mapResult.put("code", 200);
            return mapResult;
        } else {
            mapResult.put("msg", "error");
            mapResult.put("code", 500);
            return mapResult;
        }
    }

    @Override
    public Map<String, Object> deleteCard(Long id) {
        Map<String, Object> mapResult = new HashMap<>();
        Integer deleteFlag = couponCardDao.deleteCard(id);
        if (deleteFlag >= 0) {
            mapResult.put("msg", "ok");
            mapResult.put("code", 200);
            return mapResult;
        } else {
            mapResult.put("msg", "error");
            mapResult.put("code", 500);
            return mapResult;
        }
    }
}
